<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>BOOST_HOF_RETURNS &#8212; Boost.HigherOrderFunctions 0.6 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/boostbook.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '0.6',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="tap" href="tap.html" />
    <link rel="prev" title="pack" href="pack.html" /> 
  </head>
  <body role="document">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86"src="../../../_static/boost.png"></td>
</tr></table>

<div class="spirit-nav">
<a accesskey="p"  href="pack.html"><img src="../../../_static/prev.png" alt="Prev"></a>
<a accesskey="u" href="../../../doc/src/reference.html"><img src="../../../_static/up.png" alt="Up"></a>
<a accesskey="h" href="../../../doc/index.html"><img src="../../../_static/home.png" alt="Home"></a>
<a accesskey="n"  href="tap.html"><img src="../../../_static/next.png" alt="Next"></a>
</div>
  

    <div class="document">
  <div class="chapter">
      <div class="body" role="main">
        
  <div class="section" id="boost-hof-returns">
<h1>BOOST_HOF_RETURNS<a class="headerlink" href="#boost-hof-returns" title="Permalink to this headline">¶</a></h1>
<div class="section" id="header">
<h2>Header<a class="headerlink" href="#header" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;boost/hof/returns.hpp&gt;</span><span class="cp"></span>
</pre></div>
</div>
</div>
<div class="section" id="description">
<h2>Description<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal"><span class="pre">BOOST_HOF_RETURNS</span></code> macro defines the function as the expression
equivalence. It does this by deducing <code class="docutils literal"><span class="pre">noexcept</span></code> and the return type by
using a trailing <code class="docutils literal"><span class="pre">decltype</span></code>. Instead of repeating the expression for the
return type, <code class="docutils literal"><span class="pre">noexcept</span></code> clause and the function body, this macro will
reduce the code duplication from that.</p>
<p>Note: The expression used to deduce the return the type will also
constrain the template function and deduce <code class="docutils literal"><span class="pre">noexcept</span></code> as well, which is
different behaviour than using C++14&#8217;s return type deduction.</p>
</div>
<div class="section" id="synopsis">
<h2>Synopsis<a class="headerlink" href="#synopsis" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="cp">#define BOOST_HOF_RETURNS(...) </span>
</pre></div>
</div>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;boost/hof.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;cassert&gt;</span><span class="cp"></span>

<span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="p">,</span> <span class="k">class</span> <span class="nc">U</span><span class="o">&gt;</span>
<span class="k">auto</span> <span class="n">sum</span><span class="p">(</span><span class="n">T</span> <span class="n">x</span><span class="p">,</span> <span class="n">U</span> <span class="n">y</span><span class="p">)</span> <span class="n">BOOST_HOF_RETURNS</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">);</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">assert</span><span class="p">(</span><span class="mi">3</span> <span class="o">==</span> <span class="n">sum</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="incomplete-this">
<h2>Incomplete this<a class="headerlink" href="#incomplete-this" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="id1">
<h2>Description<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<p>On some non-conformant compilers, such as gcc, the <code class="docutils literal"><span class="pre">this</span></code> variable cannot
be used inside the <code class="docutils literal"><span class="pre">BOOST_HOF_RETURNS</span></code> macro because it is considered an
incomplete type. So the following macros are provided to help workaround
the issue.</p>
</div>
<div class="section" id="id2">
<h2>Synopsis<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="c1">// Declares the type of the `this` variable</span>
<span class="cp">#define BOOST_HOF_RETURNS_CLASS(...) </span>
<span class="c1">// Used to refer to the `this` variable in the BOOST_HOF_RETURNS macro</span>
<span class="cp">#define BOOST_HOF_THIS</span>
<span class="c1">// Used to refer to the const `this` variable in the BOOST_HOF_RETURNS macro</span>
<span class="cp">#define BOOST_HOF_CONST_THIS</span>
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>Example<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;boost/hof.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;cassert&gt;</span><span class="cp"></span>

<span class="k">struct</span> <span class="n">add_1</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="n">a</span><span class="p">;</span>
    <span class="n">add_1</span><span class="p">()</span> <span class="o">:</span> <span class="n">a</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">{}</span>
    
    <span class="n">BOOST_HOF_RETURNS_CLASS</span><span class="p">(</span><span class="n">add_1</span><span class="p">);</span>
    
    <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span>
    <span class="k">auto</span> <span class="k">operator</span><span class="p">()(</span><span class="n">T</span> <span class="n">x</span><span class="p">)</span> <span class="k">const</span> 
    <span class="n">BOOST_HOF_RETURNS</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">BOOST_HOF_CONST_THIS</span><span class="o">-&gt;</span><span class="n">a</span><span class="p">);</span>
<span class="p">};</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">assert</span><span class="p">(</span><span class="mi">3</span> <span class="o">==</span> <span class="n">add_1</span><span class="p">()(</span><span class="mi">2</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="mangling-overloads">
<h2>Mangling overloads<a class="headerlink" href="#mangling-overloads" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="id4">
<h2>Description<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h2>
<p>On older compilers some operations done in the expressions cannot be
properly mangled. These macros help provide workarounds for these
operations on older compilers.</p>
</div>
<div class="section" id="id5">
<h2>Synopsis<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cpp"><div class="highlight"><pre><span></span><span class="c1">// Explicitly defines the type for name mangling</span>
<span class="cp">#define BOOST_HOF_MANGLE_CAST(...) </span>
<span class="c1">// C cast for name mangling</span>
<span class="cp">#define BOOST_HOF_RETURNS_C_CAST(...) </span>
<span class="c1">// Reinterpret cast for name mangling</span>
<span class="cp">#define BOOST_HOF_RETURNS_REINTERPRET_CAST(...) </span>
<span class="c1">// Static cast for name mangling</span>
<span class="cp">#define BOOST_HOF_RETURNS_STATIC_CAST(...) </span>
<span class="c1">// Construction for name mangling</span>
<span class="cp">#define BOOST_HOF_RETURNS_CONSTRUCT(...) </span>
</pre></div>
</div>
</div>
</div>


      </div>
  </div>
      <div class="clearer"></div>
    </div>
    <div class="footer" role="contentinfo">
    <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
    <td align="left"></td>
    <td align="right"><div class="copyright-footer">
            &#169; Copyright 2016, Paul Fultz II.
        
          Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.6.
          <p>Distributed under the Boost Software License, Version 1.0.
          (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
          <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
          </p>
    </div></td>
    </tr></table>
    </div>
  </body>
</html>